Python introduction
Python is a dynamic, interpreted (bytecode-compiled) language.
There are no type declarations of variables, parameters, functions, or methods in source code. This makes the code short and flexible.
Python Source Code
Python source files uses the ``.py" extension. With a Python file ``hello.py", one way to run it is with the shell command ``python hello.py input_argument".
If the python file ``hello.py" is stored in computer, we can type shell command ``python hello.py input_argument" in terminal (command line) to run it.
This shell command ``python hello.py input_argument" calls the Python interpreter to execute the code in ``hello.py", passing it the command line argument ``input_argument".

Fig. shows a simple ``hello.py" program, and note that blocks of code are delimited strictly using identation rather than curly braces.

Fig. shows the operations for running ``hello.py" program from the command line.
Imports, Command-line arguments, and Len()
The statements in module run from top to bottom the first time the module is imported, and they set up variables and functions.
A python module can run directly, or it can be imported and used by other module.
For example, the above ``python hello.py Bob" is a python module run directly.
The special variable ``__ name__" is set to " __main__". Therefore, it is common to have the boilerplate if "__name__==..." shown above to call a main() function when the module is run directly,
In general, "len()" can tell you how long a string is, the number of elements in list and tuples, and the number of key-value pairs in a dictionary.
User-defined functions

Fig. shows the functions defined in Python.
The codes grouped by having the same level of indentation make up some function.
Two different ways to repeat strings are presented.
Using the +operator is the first option, and it is user-friendly.
* also works because it is Python's "repeat" operator, meaning that '-' * 10 gives '----------'. In the code comment, *works faster than +.
Both + and * are called overloaded operator because they mean different things for numbers vs. for strings (and other data types).
The "def" keyword defines the function with its parameters within parentheses and its code indented. The first line of a function can be a documentation string ("doctoring") that describes what the function does. The doctoring can be a single line, or a multi-line description as in the example above.
Variables defined in the function are local to that function, so the "result" in the above function is separate from a "result" variable in another function.
The "return" statement can take an argument, in which case that is the value returned to the caller.

Fig. shows code that calls the above repeat() function, and print what it returns.
At run time, function must be defined by the execution of a "def" before they are called. It is typical to def a main() function towards the bottom of the file with the functions it calls above it.
Indentation
One Python feature is that the white space indentation of a piece of code affects its meaning.
A logical block of statements such as the ones that make up a function should have the same indentation, set in from the indentation of their parent function or "if-statement". If one of the lines in a group has a different indentation, it is flagged as a syntax error.
Python's use of white space is logical. Avoid using TABs as they greatly complicate the indentation scheme. Set your editor to insert spaces instead of Table for Python code.
According to the official Python style guide (PEP 8), indent with 4 spaces is suggested.
Code Checked at Runtime
Python does little checking at compile time, differing almost all type, name, ..., check on each line until that line runs.
Suppose the above main() calls repeat() as following figure,

The If-statement contains an obvious error, where the repeat() function is accidentally typed in as repreeeet().
This code in Python compiles and runs fine so long as the name at untie is not 'Guido'.
Only when a run actually tries to execute the repeeeet() will it notice that there is no such function and raise an error.
Variable names
Python variables do not have any type spelled out in the source code, and it is helpful to give meaningful names to variables to remind yourself.
It is suggested to use "name" if it is a single name, and "names" if it is a list of names, and "tuples" if it is a list of tuples.
Some languages prefer underscored_parts for variable names made up of "more than one word", but other languages prefer camelCasing.
Python. prefers the underscore method generally.
Keywords like 'print' and 'while' can not be used as variable names.
Do not use built-ins, such as str' and 'list', as variable names.
Those system variables will be overrided. Built-ins are not keywords, and are susceptible to inadvertent use by new Python developers.
More on modules and their namespaces
Suppose you've got a module "blinky.py" which contains a "def foo()". The fully qualified name of that foo function is "blinky.foo".
In this way, various Python modules can name their functions and variables, and the variable names won't conflict.
module1.foo is different from module2.foo.
In the python vocabulary, each "blinky", "module1" and "module2" have their "namespaces".
For example, we have the standard "sys" module that contains some standard system facilities, like the arg list, and exit() function. With the statement "import sys", you can then access the definitions in the sys module and make them available by their fully-qualified name, e.g. sys.exit().

There is another import form that looks like this: "from sys import arg, exit". That makes arg and exit() available by their short names; however, the original form with the fully-qualified names is recommended because it is easier to determine where a function or attribute came from.
There are many modules and packages which are bundled with a standard installation of the Python interpreter. These are collectively known as the "Python Standard Library". Commonly used modules/packages include:
sys- access to exit(), arg, stdin, stdout, ...
re - regular expressions.
os - operating system interface, file system
Oline help help(), and dir()
There are various way to get help for Python:
Do a google search, starting with the word "python" like "python list" or "python string lowercase". The first hit is often the answer.
The official Python docs site - docs.python.org- has high quality docs.
There is also an official Tutor mailing list specifically designed for those who are new to python and/oro programming.
Many questions can be found on StakOverflow and Quora.
Use the help() and dir() functions.
Inside the Python interpreter, the help() function pulls up documentation strings for various modules, functions, and methods. The dir() function tells you what the attributes of an object are.